﻿<Window x:Class="ResourceBlender.Express.WinAddElement"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:loc="clr-namespace:ResourceBlender.Express"
    xmlns:validators="clr-namespace:ResourceBlender.Express.Validators"
    loc:WindowService.EscapeClosesWindow="True"
    Title="Add Element" Loaded="Window_Loaded"
    MinHeight="310" MinWidth="380" Height="310" Width="400"
    SizeToContent="Height" WindowStartupLocation="CenterOwner"
    Style="{StaticResource {x:Type Window}}" Icon="/ResourceBlenderExpress;component/Resources/images/resourceblender.ico">
    <Window.CommandBindings>
        <CommandBinding Command="loc:ResourceBlenderCommands.AutoTranslate" Executed="AutoTranslate" />
        <CommandBinding Command="loc:ResourceBlenderCommands.ExpandAll" Executed="ExpandAll" />
        <CommandBinding Command="loc:ResourceBlenderCommands.FindSimilar" Executed="FindSimilar" />
        <CommandBinding Command="loc:ResourceBlenderCommands.OpenFullEditor" Executed="ShowFullEditor" />
        <CommandBinding Command="loc:ResourceBlenderCommands.ShowPOEditor" Executed="ShowPOEditor" />
        <CommandBinding Command="loc:ResourceBlenderCommands.WordNetLookup" Executed="WordNetLookup" />
        <CommandBinding Command="ApplicationCommands.Close" Executed="CloseWindow" />
        <CommandBinding Command="ApplicationCommands.Help" Executed="ShowHelp" />
        <CommandBinding Command="ApplicationCommands.Save" Executed="Save" />
        <CommandBinding Command="NavigationCommands.Favorites" Executed="ShowShortcuts" />
        <CommandBinding Command="NavigationCommands.GoToPage" Executed="GoToTranslation" />
        <CommandBinding Command="NavigationCommands.NextPage" Executed="MoveElement" CanExecute="CanMoveNext" />
        <CommandBinding Command="NavigationCommands.PreviousPage" Executed="MoveElement" CanExecute="CanMovePrevious" />
    </Window.CommandBindings>
    <Window.InputBindings>
        <KeyBinding Command="ApplicationCommands.Save" Gesture="Ctrl+S" />
        <KeyBinding Command="NavigationCommands.NextPage" Gesture="Alt+Right" />
        <KeyBinding Command="NavigationCommands.PreviousPage" Gesture="Alt+Left" />
    </Window.InputBindings>
    <Window.Resources>
        <ObjectDataProvider x:Key="dataProvider" />
    </Window.Resources>
    <DockPanel LastChildFill="True" >
        <DockPanel DockPanel.Dock="Top" LastChildFill="True" HorizontalAlignment="Stretch" Width="Auto">
            <ToolBar DockPanel.Dock="Right" BorderThickness="0,0,1,1">
                <loc:ImageButton x:Uid="loc:ImageButton_1" Command="NavigationCommands.Favorites" Text="Shortcut Keys" Image="Resources/images/help_keyboard_24.png" ShowText="False" ToolTip="Shortcut Keys" Style="{StaticResource ToolBarButton}" />
                <loc:ImageButton x:Uid="loc:ImageButton_2" Command="ApplicationCommands.Help" Text="Show Help" Image="Resources/images/question_24.png" ShowText="False" ToolTip="Managing Elements" Style="{StaticResource ToolBarButton}" />
            </ToolBar>
            <ToolBar DockPanel.Dock="Left" BorderThickness="1,0,0,1">
                <loc:ImageButton x:Uid="loc:ImageButton_3" Command="ApplicationCommands.Save" IsDefault="True" Text="Save" Image="Resources/images/save_24.png" ShowText="False" ToolTip="Save and Close" Style="{StaticResource ToolBarButton}" />
                <loc:ImageButton x:Uid="loc:ImageButton_4" Command="loc:ResourceBlenderCommands.ShowPOEditor" Text="OpenPOEditor" Image="Resources/images/gnu_32.png" ShowText="False" ToolTip="Edit this element as a PO entry" Style="{StaticResource ToolBarButton}" />
                <loc:ImageButton x:Uid="loc:ImageButton_5" Command="NavigationCommands.PreviousPage" Text="Previous" Image="Resources/images/previous_32.png" ShowText="False" ToolTip="Save and move to the previous element" Style="{StaticResource ToolBarButton}" />
                <loc:ImageButton x:Uid="loc:ImageButton_6" Command="NavigationCommands.NextPage" Text="Next" Image="Resources/images/next_32.png" ShowText="False" ToolTip="Save and move to the next element" Style="{StaticResource ToolBarButton}" />
            </ToolBar>
        </DockPanel>
        
        <StatusBar DockPanel.Dock="Bottom" Height="24">
            <StatusBarItem x:Name="lblStatus" Visibility="Hidden">Loading</StatusBarItem>
            <ProgressBar x:Name="prgStatus" IsIndeterminate="True" Visibility="Hidden" />
        </StatusBar>
        
        <Grid x:Name="grdContainer" DockPanel.Dock="Top" Margin="6">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Label Grid.Row="0" Grid.Column="0">Element Name</Label>
            <TextBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" x:Name="txtElement" TabIndex="0">
                <Binding Path="Name" Source="{StaticResource dataProvider}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" >
                    <Binding.ValidationRules>
                        <validators:StringValidationRule x:Uid="validators:StringValidationRule_1" MinimumLength="0" MaximumLength="255" ErrorMessage="Element name must be between 1 and 255 characters" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox>
            
            <Label Grid.Row="1" Grid.Column="0" ToolTip="Comments about the element. Eg: Where it's used">Comment</Label>
            <TextBox Grid.Row="1" Grid.Column="1" x:Name="txtComment" TabIndex="1" Text="{Binding Path=Comment,Source={StaticResource dataProvider},Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" MaxHeight="80" VerticalScrollBarVisibility="Auto" />
            <loc:ImageButton x:Uid="loc:ImageButton_7" Grid.Row="1" Grid.Column="2" Image="Resources/images/expand_16.png" ShowText="False" ToolTip="Edit this field using the full editor" Margin="1,1,0,1"
                             Command="loc:ResourceBlenderCommands.OpenFullEditor" CommandTarget="{Binding ElementName=txtComment}" />
                    
            <Label Grid.Row="2" Grid.Column="0">Bundle</Label>
            <ComboBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" x:Name="cboBundle" TabIndex="2" DisplayMemberPath="Value" SelectedValue="{Binding Path=BundleID,Source={StaticResource dataProvider},Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" SelectedValuePath="Key"></ComboBox>
            
            <Label Grid.Row="3" Grid.Column="0">Resource</Label>
            <ComboBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" x:Name="cboResource" TabIndex="3" SelectedValue="{Binding Path=Resource.ID,Source={StaticResource dataProvider},Mode=OneWay}" SelectedValuePath="Key" SelectionChanged="cboResource_SelectionChanged">
                <ComboBox.Template> <!-- Use to show resource ID and translation for default language -->
                    <ControlTemplate TargetType="ComboBox">
                        <Grid>
                            <ToggleButton Name="ToggleButton" Template="{StaticResource ComboBoxToggleButton}" Grid.Column="2" TabIndex="4" Focusable="false"
                                        IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press">
                            </ToggleButton>
                            <ContentPresenter Name="ContentSite" IsHitTestVisible="False" Margin="3,1,23,1" VerticalAlignment="Center" HorizontalAlignment="Left"
                                  Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" />
                            <TextBox x:Name="PART_EditableTextBox" Style="{x:Null}" Template="{StaticResource ComboBoxTextBox}" 
                                     HorizontalAlignment="Left" VerticalAlignment="Center" Margin="3,3,23,3" Focusable="True" Background="Transparent" Visibility="Hidden" 
                                     IsReadOnly="{TemplateBinding IsReadOnly}"/>
                            <Popup Name="Popup" Placement="Bottom" PopupAnimation="Slide" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False">
                                <Grid Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}">
                                    <Border x:Name="DropDownBorder" Background="{StaticResource WindowBackgroundBrush}" BorderThickness="1" BorderBrush="{StaticResource SolidBorderBrush}"/>
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="*" />
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        
                                        <TextBlock Grid.Row="0" Grid.Column="0" Text="Resource ID" Margin="4" FontWeight="Bold" VerticalAlignment="Center" />
                                        <TextBlock Grid.Row="0" Grid.Column="1" Text="Translation" Margin="4" FontWeight="Bold" VerticalAlignment="Center" HorizontalAlignment="Right" />
                                        <ScrollViewer Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="4,6,4,6" SnapsToDevicePixels="True">
                                            <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
                                        </ScrollViewer>
                                    </Grid>
                                </Grid>
                            </Popup>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
                                <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="2"/>
                                <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </ComboBox.Template>
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock TextTrimming="CharacterEllipsis" Width="180" HorizontalAlignment="Left">
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0} - {1}">
                                    <Binding Path="Key" />
                                    <Binding Path="Value" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            
            <Label Grid.Row="4" Grid.Column="0" ToolTip="Comments about the resource. Eg: Where it's used">Resource Comment</Label>
            <TextBox Grid.Row="4" Grid.Column="1" x:Name="txtResourceComment" TabIndex="5" Text="{Binding Path=Resource.Comment,Source={StaticResource dataProvider},Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" MaxHeight="80" VerticalScrollBarVisibility="Auto"  />
            <loc:ImageButton x:Uid="loc:ImageButton_8" Grid.Row="4" Grid.Column="2" Image="Resources/images/expand_16.png" ShowText="False" ToolTip="Edit this field using the full editor" Margin="1,1,0,1"
                             Command="loc:ResourceBlenderCommands.OpenFullEditor" CommandTarget="{Binding ElementName=txtResourceComment}" />
            
            <Expander Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3" x:Name="expTranslations" Header="Translations" Margin="0,4,0,2" VerticalContentAlignment="Top">
                <ScrollViewer VerticalScrollBarVisibility="Auto"  MaxHeight="500" HorizontalContentAlignment="Stretch">
                    <StackPanel HorizontalAlignment="Stretch">
                        <Button Command="loc:ResourceBlenderCommands.ExpandAll" MinWidth="140" HorizontalAlignment="Left">Expand All Translations</Button>
                        <StackPanel x:Name="stkTranslations" VerticalAlignment="Stretch" />
                    </StackPanel>
                </ScrollViewer>
            </Expander>
        </Grid>
    </DockPanel>
</Window>
